﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class ServicesSheet_PlaneTicketList : System.Web.UI.Page
{
    private Srvtools.WebDataSet WMaster;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();

            MasterPage_MasterPage master = (MasterPage_MasterPage)this.Page.Master;
            master.HelpHref = "~/Help/ServicesSheet/机票申请列表.htm";
            master.PageName = "机票申请列表";
            master.PicUrl = "";
            master.IntiBar();
        }
    }

    private void InitializeComponent()
    {
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ServicesSheet_PlaneTicketList));
        this.WMaster = new Srvtools.WebDataSet();
        ((System.ComponentModel.ISupportInitialize)(this.WMaster)).BeginInit();
        // 
        // WMaster
        // 
        this.WMaster.Active = true;
        this.WMaster.AlwaysClose = false;
        this.WMaster.DeleteIncomplete = true;
        this.WMaster.Guid = null;
        this.WMaster.LastKeyValues = null;
        this.WMaster.Locale = new System.Globalization.CultureInfo("zh-CN");
        this.WMaster.PacketRecords = 100;
        this.WMaster.Position = -1;
        this.WMaster.RemoteName = "ServiceSheet.View_Services_PlaneTicket";
        this.WMaster.ServerModify = false;
        ((System.ComponentModel.ISupportInitialize)(this.WMaster)).EndInit();

    }

    void LoadData()
    {
        InitializeComponent();
        string where = "";
        //非管理员只能查看自已的单据
        if (Srvtools.CliUtils.fGroupID.IndexOf(System.Configuration.ConfigurationManager.AppSettings["FlowAdmin"].ToString()) == -1)
        {
            String wh = " Services_PlaneTicket.EmpId ='" + Convert.ToInt32(Srvtools.CliUtils.fLoginUser).ToString() + "'";
                where = wh;
        }
        else
        {
              where = "1=1";
        }
        
        if (ViewState["depId"] != null)
            where += " AND department.departmentid like '" + ViewState["depId"].ToString() + "%'";
        if (ViewState["month"] != null)
            where += " AND month(Services_PlaneTicket.ApDate)='" + ViewState["month"].ToString() + "'";
        if (ViewState["year"] != null)
            where += " AND year(Services_PlaneTicket.ApDate)='" + ViewState["year"].ToString() + "'";
        if (ViewState["state"] != null)
            where += " AND Services_PlaneTicket.FlowFlag='" + ViewState["state"].ToString() + "'";
        this.WMaster.SetWhere(where);

        Master.DataSource = WMaster;
    }

    protected void btnSerch_Click(object sender, EventArgs e)
    {
        string depId = this.DepartmentDList1.SelectDepmanetId;
        string month = this.DSelYearMonth1.SelectMonth;
        string year = this.DSelYearMonth1.SelectYear;
        string state = this.WebDropDownList1.SelectedValue;
        if (depId != "0")
            ViewState["depId"] = depId;
        if (month != "0")
            ViewState["month"] = month;
        if (year != "0")
            ViewState["year"] = year;
        if (state != "")
            ViewState["state"] = state;

        LoadData();

        ViewState.Clear();
    }

    protected void WebGridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            DataRowView drv = (DataRowView)e.Row.DataItem;
            System.Web.UI.WebControls.ImageButton _ibtn = e.Row.FindControl("ibtnDelete") as System.Web.UI.WebControls.ImageButton;
            if (_ibtn != null)
            {
                _ibtn.Visible = false;
                string _Roles = ";" + Srvtools.CliUtils.Roles + ";";
                if (_Roles.IndexOf(";R705;") != -1) //有权限
                {
                    if (drv["FlowFlag"].ToString() == "X" || drv["FlowFlag"].ToString() == "") //已走流程不可以删除
                    {
                        _ibtn.Visible = true;
                        _ibtn.Attributes.Add("onclick", "return window.confirm('您确信删除此项记录吗?');");
                    }
                }
            }
        }
    }
    protected void WebNavigator1_Command(object sender, CommandEventArgs e)
    {
        if (e.CommandName == "cmdAdd")
        {
            Response.Redirect("PlaneTicket.aspx?FLOWFILENAME=FL\\PlaneTicket");//&NAVMODE=Inset&FLNAVMODE=Submit
        }
        else if (e.CommandName == "cmdClientQuery")
        {
            string ss = this.ResolveUrl("..\\InnerPages\\FlowDesigner.aspx") + "?FLOWFILENAME=PlaneTicket";
            Response.Write(" <script   language=javascript> window.open( '" + ss + " ','流程图','height=600,width=800,top=50,left=100,toolbar=no,menubar=no,scrollbars=yes, resizable=yes,location=no, status=no'); </script> ");
        }
    }
}
